package com.smartbone.services.impl;

import java.util.List;

import com.smartbone.dao.daoInterface.IUsersDAO;
import com.smartbone.entity.Users;
import com.smartbone.services.interfaces.UserService;

public class UserServiceImpl implements UserService {

	private IUsersDAO userDAO;
	
	public IUsersDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(IUsersDAO userDAO) {
		this.userDAO = userDAO;
	}
	
	public List<Users> listAllUser() {
		
		return userDAO.findAll();
	}

	public List<Users> listAllUserWithPageSize(int startRow, int pageSize) {
		
		return userDAO.findAllWithPageSize(startRow, pageSize);
	}
	
	public String findAllUserCount() {
		
		return userDAO.findAllUserCount();
	}
	
	public void registeUser(Users user) {
		userDAO.save(user);

	}

	public Users findByUserName(String username) {
		
		Users loginedUser = null;
		
		if (username != null) {
			List<Users> userList = userDAO.findByUsername(username);
			
			if (userList != null && !userList.isEmpty()) {
				loginedUser = userList.get(0);
			}
		}
		
		return loginedUser;
	}
	
	public void updateUser(Users user){
		
		userDAO.update(user);
		
	}

}
